package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.exartisan.yn_event.R;
import com.loopj.android.image.SmartImageView;

public class LazyAdapter extends BaseAdapter
{
	private ArrayList<String> data;
	private LayoutInflater inflater;

	public LazyAdapter(Context ctx, ArrayList<String> d){
		this.data = d;
		inflater = LayoutInflater.from(ctx);
	}

	public int getCount()
	{
		return data.size();
	}

	public Object getItem(int position)
	{
		return position;
	}

	public long getItemId(int position)
	{
		return position;
	}

	public View getView(int pos, View convertView, ViewGroup parent)
	{
		ViewHolder holder;
		if (convertView == null){
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.row_gridview_img, null);
			holder.imgThumb = (SmartImageView) convertView.findViewById(R.id.item_img);
			convertView.setTag(holder);
		} else
			holder = (ViewHolder) convertView.getTag();
		holder.imgThumb.setImageUrl(data.get(pos));
		return convertView;
	}
	
	class ViewHolder{
		SmartImageView imgThumb;
	}
}